package com.br.semperparata.components.gui;

import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JSpinner.ListEditor;

public class MinuteSpinner extends JPanel {
	private static final long serialVersionUID = 1L;

	private JSpinner spinner = null;
	private JLabel label = null;
	
	private MinuteSpinnerModel model;
	
	public MinuteSpinner() {
		this(null, 0, 0);
	}
	
	public MinuteSpinner(String label) {
		this(label, 0, 0);
	}
	
	public MinuteSpinner(String label, int duration, int increment) {
		super(new FlowLayout(FlowLayout.LEADING, 5, 5));
		this.model = new MinuteSpinnerModel(duration, increment);
		if (label != null) {
			this.label = new JLabel(label);
			this.add(this.label);
		}
		
		this.spinner = new JSpinner(model);
		ListEditor editor = new ListEditor(spinner);
		editor.getTextField().setEditable(false);
		this.spinner.setEditor(editor);
		
		this.add(this.spinner);
	}
	
	public void setLabelFont(Font font) {
		if (this.label != null)
			this.label.setFont(font);
	}
	
	public void setSpinnerFont(Font font) {
		this.spinner.setFont(font);
	}
	
	public void setFonts(Font font) {
		setLabelFont(font);
		setSpinnerFont(font);
	}
}
